package com.zzyl.job;


import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.zzyl.nursing.domain.Contract;
import com.zzyl.nursing.mapper.ContractMapper;
import com.zzyl.nursing.service.IContractService;
import org.apache.poi.ss.formula.functions.Now;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.List;

@Component("UpdateContractStatusJob")
public class UpdateContractStatusJob {

    @Autowired
    private ContractMapper contractMapper;
    @Autowired
    private IContractService contractService;

    public void ryNoParams()
    {
        LambdaUpdateWrapper<Contract> upWrapper = new LambdaUpdateWrapper<>();
        upWrapper.set(Contract::getStatus,1);
        upWrapper.eq(Contract::getStatus,0);
        upWrapper.lt(Contract::getStartDate,LocalDateTime.now());
        upWrapper.gt(Contract::getEndDate,LocalDateTime.now());
        contractService.update(upWrapper);

        LambdaUpdateWrapper<Contract> upWrapper1 = new LambdaUpdateWrapper<>();
        upWrapper1.set(Contract::getStatus,2);
        upWrapper1.eq(Contract::getStatus,1);
        upWrapper1.lt(Contract::getEndDate,LocalDateTime.now());
        contractService.update(upWrapper1);
    }
}

/* System.out.println("执行无参方法");
        LambdaQueryWrapper<Contract> queryWrapper = new LambdaQueryWrapper<>();
        List<Contract> contracts = contractMapper.selectList(queryWrapper);
        for (Contract c : contracts) {
            LocalDateTime startDate = c.getStartDate();
            LocalDateTime endDate = c.getEndDate();
            LocalDateTime now = LocalDateTime.now();
            if (now.isBefore(startDate)) {
                c.setStatus(0);
            }else if (!now.isBefore(startDate) && !now.isAfter(endDate)) {
                c.setStatus(1);
            }else if(now.isAfter(startDate)){
                c.setStatus(2);
            }else{
                c.setStatus(3);
            }
            contractMapper.updateById(c);
        }*/
